const watch = require('node-watch')
const cpFile = require('cp-file')

console.log('start watch file...')
watch('./', { recursive: true }, async function (evt, name) {
    if (name === 'index.js' || name === 'package.json'
        || name.indexOf('doc/') >= 0 || name.indexOf('doc\\') >= 0
        || name.indexOf('.vscode/') >= 0 || name.indexOf('.vscode\\') >= 0
        ) return

    console.log(name)
    if (evt === 'update') {
        await cpFile(name, `../client/${name}`)
        await cpFile(name, `../server/${name}`)

        console.log(`copy file success: ${name} => ../client/src/common/${name}, ../server/src/common/${name}`)
    } else {
        console.error(`需要手动删除文件：${name}`)
    }
})